package example.my_practice;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import example.entity.User;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author guoQ.z
 * @date 2020/11/27 17:32
 * TODO
 */
public class JsonObjPractice {
    public static void main2(String[] args) {
        User u1 = new User();
        u1.setDate(new Date());
        String s = JSON.toJSONString(u1);
        System.out.println(s);
        User user = JSONObject.parseObject(s, User.class);
        System.out.println(user);
    }

    public static void main(String[] args) {
        List<User> list = new ArrayList<>();
        User u1 = new User();
        u1.setDate(new Date());
        list.add(u1);
        String s = JSON.toJSONString(list);
        System.out.println(s);
        List<User> users = JSONArray.parseArray(s, User.class);
        System.out.println(users);
    }
}
